package com.connector.base.message.model;

import com.alibaba.fastjson.JSONObject;
import com.connector.base.connection.Connection;
import com.connector.base.protocol.Command;
import com.connector.base.protocol.Packet;

public final class KickUserMessage extends JsonBodyMessage
{
    public String deviceId;
    public String userId;

    public KickUserMessage(final Packet packet, final Connection connection) {
        super(packet, connection);
    }

    @Override
    public void jsonToFields(final JSONObject jsonBody) {
        this.deviceId = (jsonBody.containsKey((Object)"deviceId") ? jsonBody.getString("deviceId") : null);
        this.userId = (jsonBody.containsKey((Object)"userId") ? jsonBody.getString("userId") : null);
    }

    @Override
    public JSONObject fieldToJson() {
        final JSONObject resultObj = new JSONObject();
        resultObj.put("deviceId", (Object)this.deviceId);
        resultObj.put("userId", (Object)this.userId);
        return resultObj;
    }

    public KickUserMessage buildResponse() throws Exception {
        KickUserMessage kickRespMessage = null;
        if (0 == this.packet.getType()) {
            kickRespMessage = new KickUserMessage(new Packet(Command.KICK.cmd, (byte)1), this.connection);
        }
        else if (2 == this.packet.getType()) {
            kickRespMessage = new KickUserMessage(new Packet(Command.KICK.cmd, (byte)4), this.connection);
        }
        if (kickRespMessage == null) {
            throw new Exception("unknown package request type");
        }
        return kickRespMessage;
    }

    public static KickUserMessage build(final Connection connection) {
        return new KickUserMessage(new Packet(Command.KICK.cmd), connection);
    }

    public KickUserMessage() {
    }
}
